package com.sun.designpatternsdemo.iterator

/**
 * 版权：xx公司 版权所有
 * @author sun
 * 版本：1.0
 * 创建日期：2021/7/1 15:13
 * 描述：
 *创建接口
 */
interface Iterator{
    fun hasNext():Boolean

    fun next():Any?
}

interface Container{
    fun getIterator():Iterator
}

class NameRepository:Container{
    val names = arrayOf("John", "jingbin", "youlookwhat", "lookthis")
    override fun getIterator(): Iterator {
        return NameIterator()
    }
    inner class NameIterator:Iterator{
        private var index:Int = 0
        override fun hasNext(): Boolean {
            if (index<names.size){
                return true
            }
            return false
        }

        override fun next(): Any? {
            if (hasNext()){
                return names[index++]
            }
            return null
        }

    }


}